package com.rgc.web;



import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;





import com.rgc.dao.PublicacionDao;
import com.rgc.domain.Publicacion;
import com.rgc.domain.Usuario;
import com.rgc.domain.form.Propaganda;

@ControllerAdvice

public class ControladorGlobal {
	

	
	protected final Log logger = LogFactory.getLog(getClass());
    ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
    protected PublicacionDao publicacionDao = (PublicacionDao) context.getBean("publicacionDao");
  
    
    @ModelAttribute("usuarioLogin")
    public Usuario populateForm() {
    	
    	return new Usuario();
    }
    
    
    
    @ModelAttribute("propaganda")
    public Propaganda populateFormPropaganda() {
    	List<Publicacion> publicacion=publicacionDao.listPropaganda();
    	Propaganda propaganda=new Propaganda();
    	System.out.println(publicacion.size());
    	propaganda.setPublicidad(publicacion);
    	System.out.println(propaganda.getPublicidad().size());
    	return propaganda;
	}
    

    
}